//
//  QYGDollBottomView.m
//  wawaji_ios
//
//  Created by 奇艺果 on 2018/2/7.
//  Copyright © 2018年 yiguo qi. All rights reserved.
//

#import "QYGDollBottomView.h"


#define kJDollBottomViewHeight ScaleW(149)

@interface QYGDollBottomView()
@property (weak, nonatomic) IBOutlet UIButton *topBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;
@property (weak, nonatomic) IBOutlet UIButton *downBtn;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;

@property (weak, nonatomic) IBOutlet UIButton *grabBtn;
@property (weak, nonatomic) IBOutlet UIButton *detailBtn;
@property (weak, nonatomic) IBOutlet UIButton *startBtn;
@property (weak, nonatomic) IBOutlet UILabel *coinLabel;
@property (weak, nonatomic) IBOutlet UILabel *onceCoinLabel;
@property (weak, nonatomic) IBOutlet UIImageView *dollCoinImg;
@property (weak, nonatomic) IBOutlet UIImageView *dollCoinStrImg;
@property (weak, nonatomic) IBOutlet UIButton *rechargeBtn;

@end


@implementation QYGDollBottomView

+ (instancetype)dollBottomView {
    QYGDollBottomView *dollBottomView = [[[NSBundle mainBundle] loadNibNamed:@"QYGDollBottomView" owner:nil options:nil] firstObject];
    dollBottomView.height = kJDollBottomViewHeight;
    
    return dollBottomView;
}

- (void)updateTotalCoin:(NSString *)totalCoin{
    self.coinLabel.text = totalCoin;
    
}
- (void)updateOnceCoin:(NSString *)onceCoin{
    self.onceCoinLabel.text = onceCoin;
}
- (void)setIsHiddenStartView:(BOOL)isHiddenStartView{
    _isHiddenStartView = isHiddenStartView;
    self.startView.hidden = isHiddenStartView;
}
- (void)setStarBtnMode:(CatchStartBtnMode)starBtnMode{
    _starBtnMode = starBtnMode;
    switch (starBtnMode) {
        case CatchStartBtnModeCanStart:// 可以开始游戏
        {
            [self.startBtn setImage:[UIImage imageNamed:@"doll_btn_start_nor"] forState:UIControlStateNormal];
            [self.startBtn setImage:[UIImage imageNamed:@"doll_btn_start_click"] forState:UIControlStateHighlighted];
            self.onceCoinLabel.textColor = [UIColor colorWithHex:@"c26b13"];
            self.onceCoinLabel.hidden = NO;
        }
            break;
        case CatchStartBtnModeCanOrder:// 可以排队
        {
            [self.startBtn setImage:[UIImage imageNamed:@"doll_btn_order_nor"] forState:UIControlStateNormal];
            [self.startBtn setImage:[UIImage imageNamed:@"doll_btn_order_click"] forState:UIControlStateHighlighted];
            self.onceCoinLabel.textColor = [UIColor colorWithHex:@"139ec2"];
            self.onceCoinLabel.hidden = NO;
        }
            break;
        case CatchStartBtnModeLineup://正在排队
        {
            [self.startBtn setImage:[UIImage imageNamed:@"doll_btn_lineup_nor"] forState:UIControlStateNormal];
            self.onceCoinLabel.hidden = YES;
        }
            break;
            
        default:
            break;
    }
    
}


- (IBAction)rechargeBtnClick:(id)sender {
    if(![QYGKeychain isShowPay])
    {
        return;
    }
    if(self.rechargeBtnClickedBlock) self.rechargeBtnClickedBlock();
    
}

- (IBAction)detailBtnClick:(UIButton *)sender {
    if(self.detailBtnClickedBlock)self.detailBtnClickedBlock();
}

- (IBAction)actionButtonDownClick:(UIButton *)button {
    
    //手指按下, 移动
    NSInteger action = button.tag;
    if(self.operationDownClickedBlock)self.operationDownClickedBlock(action);
}


- (IBAction)actionButtonOnClick:(UIButton *)button {
    //手指松开, 停止
    NSInteger action = button.tag;
    if(self.operationOnClickedBlock)self.operationOnClickedBlock(action);
}

- (IBAction)startButtonOnClick:(id)sender {
    if(self.startBtnClickedBlock)self.startBtnClickedBlock(self.starBtnMode);
}
- (void)awakeFromNib{
    [super awakeFromNib];
    
    [self layoutConstraints];
}
- (void)layoutConstraints{
    [_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(ScaleW(48), ScaleW(48)));
        make.left.mas_equalTo(ScaleW(32));
        make.top.mas_equalTo(ScaleW(39));
    }];
    [_topBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ScaleW(4));
        make.left.mas_equalTo(ScaleW(80));
        make.size.mas_equalTo(CGSizeMake(ScaleW(48), ScaleW(48)));
    }];
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ScaleW(39));
        make.left.mas_equalTo(ScaleW(128));
        make.size.mas_equalTo(CGSizeMake(ScaleW(48), ScaleW(48)));
    }];
    [_downBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ScaleW(72));
        make.left.mas_equalTo(ScaleW(80));
        make.size.mas_equalTo(CGSizeMake(ScaleW(48), ScaleW(48)));
    }];
    [_grabBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(ScaleW(144), ScaleW(96)));
        make.right.mas_equalTo(ScaleW(-36));
        make.top.mas_equalTo(ScaleW(13));
    }];
    [_detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(ScaleW(50), ScaleW(67)));
        make.top.mas_equalTo(ScaleW(33));
        make.left.mas_equalTo(ScaleW(28));
    }];
    [_startBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ScaleW(21));
        make.centerX.mas_equalTo(self);
        make.size.mas_equalTo(CGSizeMake(ScaleW(184), ScaleW(92)));
    }];
    [_onceCoinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.startBtn.mas_left).offset(ScaleW(63));
        make.bottom.equalTo(self.startBtn.mas_bottom).offset(-ScaleW(25));
        make.right.equalTo(_startBtn.mas_right);
    }];
    
    
    [_dollCoinImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(ScaleW(42), ScaleW(47)));
        make.top.equalTo(self.mas_top).offset(ScaleW(28));
        make.right.equalTo(self.mas_right).offset(-ScaleW(38));
    }];
    
    [_dollCoinStrImg mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.dollCoinImg.mas_left).offset(-ScaleW(5));
        make.bottom.equalTo(self.detailBtn.mas_bottom).offset(-ScaleW(3));
        make.size.mas_equalTo(CGSizeMake(ScaleW(25), ScaleW(12)));
    }];
    
    [_coinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-5);
        make.centerY.equalTo(self.dollCoinStrImg.mas_centerY);
        make.left.equalTo(self.dollCoinStrImg.mas_right).offset(3);
    }];
    [_rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_dollCoinImg.mas_top);
        make.left.equalTo(_dollCoinImg.mas_left);
        make.right.equalTo(_coinLabel.mas_right);
        make.bottom.equalTo(_dollCoinStrImg.mas_bottom);
    }];
}
@end
